package com.dixon.worddayday.dao;

import com.dixon.worddayday.bo.FailByDayBean;
import com.dixon.worddayday.model.ReviewRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ReviewRecordRepository extends JpaRepository<ReviewRecord, Integer> {
    @Query("select count(id) from ReviewRecord where customerId= :customerId")
    int countTotal(@Param("customerId") Integer customerId);

    @Query("select count(id) from ReviewRecord where customerId= :customerId and reviewResult='2'")
    int countFail(@Param("customerId") Integer customerId);


    /**
     * 近30天每天记错的次数
     * @param customerId
     * @return
     */
    @Query(value = "select formatdatetime(create_time, 'yyyy-MM-dd') as dateStr, count(id) as num from review_record where customer_id= :customerId and review_result='2' and create_time > (current_date - 7) group by formatdatetime(create_time, 'yyyy-MM-dd') ", nativeQuery = true)
    List<FailByDayBean> countFailByDay(@Param("customerId") Integer customerId);
}
